Skip to content

Fix B103: Support stat constants and BitOr operations in os.chmod#1391

Closed
9iang22 wants to merge 1 commit into
PyCQA:mainfrom
9iang22:fix-b103-stat
Closed

Fix B103: Support stat constants and BitOr operations in os.chmod#1391
9iang22 wants to merge 1 commit into
PyCQA:mainfrom
9iang22:fix-b103-stat

Conversation

@9iang22
Copy link
Copy Markdown

@9iang22 9iang22 commented Apr 15, 2026

Fix B103 false negatives for stat-based chmod modes

B103 relied on literal mode extraction and missed chmod calls where permissions were expressed as stat constants or BitOr combinations. That created false negatives for dangerous permission settings written in common, idiomatic Python forms.

This change resolves mode values from the AST for integer constants, stat.* attributes, and | combinations so existing B103 checks apply consistently across equivalent expressions.
It also updates the chmod functional example and expected counts to cover the newly detected unsafe cases.

Resolves: #1390

Adds AST mode resolution for os.chmod to prevent false negatives, along with updated test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative: B103 fails to detect dangerous permissions set via stat module constants

1 participant